const getParameterMap = function (url) {
  if (!url) {
    url = window.location.href
  }
  let index = url.indexOf('?')
  if (index === -1 || index === url.length - 1) {
    return null
  }
  let queryStr = url.substr(url.indexOf('?') + 1)
  if (!queryStr) {
    return null
  }
  let urlArr = queryStr.split('&')
  let paraMap = {}
  for (let i = 0; i < urlArr.length; i++) {
    let paras = urlArr[i].split('=')
    if (paras.length === 2) {
      let obj = paraMap[paras[0]]
      if (obj) {
        if (!Array.isArray(obj)) {
          obj = [obj]
        }
        obj[obj.length] = paras[1]
      } else {
        obj = paras[1]
      }
      paraMap[paras[0]] = obj
    }
  }
  return paraMap
}

export default getParameterMap
